{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f2e423c6",
   "metadata": {},
   "source": [
    "-------\n",
    "* 2022/09/13/week04\n",
    "* python笔记\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df806c67",
   "metadata": {},
   "source": [
    "## 回顾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08fb9b18",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "06d388e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1008faee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8b1100e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4bdd4e66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff2ec87f",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "* type():检查类型\n",
    "> 1.数值\n",
    ">> 1.int\n",
    ">>\n",
    ">> 2.float\n",
    ">>\n",
    ">> 3.complex\n",
    ">\n",
    "> 2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c468c0a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## number(数值)\n",
    "## int\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5fafc925",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float\n",
    "b = 11.5 \n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f1576b5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数 复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0dbef47d",
   "metadata": {},
   "source": [
    "## 2.字符串(string)\n",
    "> 2.1,字符串基本内容\n",
    "> \n",
    "> 2.2,字符串方法及函数\n",
    "\n",
    "> 3.in检查成员对象\n",
    ">\n",
    "> 4.字符串拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "8d268c05",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7a036a26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "f6404d31",
   "metadata": {},
   "outputs": [],
   "source": [
    "nfu_index_pages_html = \"\"\"\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ef3a5c2",
   "metadata": {},
   "source": [
    "###  2 .2字符串方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "733f0e2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c76e6591",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "1bc9df2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1]# 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "8c05a26a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[2] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6fc757f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "619205b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "4037153b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值 称为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ea6f0e59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "816777ec",
   "metadata": {},
   "source": [
    "## enumerate 枚举，即可以获取到内容item又可以获取到 索引值index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "771ab692",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "31d6407c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在文本中\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何 判断一段文本中是否存在“广州”,例如 title 中的内容\n",
    "\n",
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1] ==\"州\":\n",
    "            print(\"广州这个词在文本中\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c524be9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 2.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "d33278e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## page 59 in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21bb0945",
   "metadata": {},
   "source": [
    "  * 字符串拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "22e25769",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\"+\",\"+\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45896cd4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串不可和数字进行连接\n",
    "# 字符串不可以运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35242216",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 错误案例\n",
    "width = \"16\"\n",
    "heigt = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "85ca432d",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'width' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [45]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m 面积 \u001b[38;5;241m=\u001b[39m \u001b[43mwidth\u001b[49m \u001b[38;5;241m*\u001b[39m heigt\n",
      "\u001b[1;31mNameError\u001b[0m: name 'width' is not defined"
     ]
    }
   ],
   "source": [
    "面积 = width * heigt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a105e016",
   "metadata": {},
   "source": [
    "* 字符串的方法\n",
    "> 1.str.capitalize():可以将首字母转成大写\n",
    ">\n",
    "> 2.str.count():数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6b58f3aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"Marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "3f01afa9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "e66be533",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "69a1de1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "de9495df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "7891f9a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州', '学院']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"南方\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b707d87",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"\"\"\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fbddd61",
   "metadata": {},
   "outputs": [],
   "source": [
    "text.split(\"的\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04be0b0f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
